// pages/community/community.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    cartCount:0,
    titleImageList: [
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/1-1.png", id: 1, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/1-2.png", id: 2, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/1-3.png", id: 3, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/1-4.png", id: 4, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/1-5.png", id: 5, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/1-6.png", id: 6, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/1-7.png", id: 7, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/1-8.png", id: 8, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/1-9.png", id: 9, animation: null },
    ],
    gongyuList: [
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/2-1.png", id: 1, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/2-2.png", id: 2, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/2-3.png", id: 3, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/2-4.png", id: 4, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/2-5.png", id: 5, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/2-6.png", id: 6, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/2-7.png", id: 7, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/2-8.png", id: 8, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/2-9.png", id: 9, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/2-10.png", id: 10, animation: null },
    ],
    yongjinList: [
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/3-1.png", id: 1, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/3-2.png", id: 2, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/3-3.png", id: 3, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/3-4.png", id: 4, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/3-5.png", id: 5, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/3-6.png", id: 6, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/3-7.png", id: 7, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/3-8.png", id: 8, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/3-9.png", id: 9, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/3-10.png", id: 10, animation: null },
    ],
    starList: [
      {
        src:
          "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/category-image/jump-image/star.png",
        id: 1,
        animation: null,
      },
      {
        src:
          "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/category-image/jump-image/star-1.png",
        id: 1,
        animation: null,
      },
    ],
    chengjiaoList: [
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/4-1.png", id: 1, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/4-2.png", id: 2, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/4-3.png", id: 3, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/4-4.png", id: 4, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/4-5.png", id: 5, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/4-6.png", id: 6, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/4-7.png", id: 7, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/4-8.png", id: 8, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/4-9.png", id: 9, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/4-10.png", id: 10, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/4-11.png", id: 11, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/4-12.png", id: 12, animation: null },
      { src: "https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/4-13.png", id: 13, animation: null },
    ],
    ERPlist:[
      {src:'https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/ERP-example/ERP.png',id:1},
      {src:'https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/ERP-example/ERPparticulars.png',id:2},
      {src:'https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/ERP-example/2-1.png',id:3},
      {src:'https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/ERP-example/2-2.png',id:4},
      {src:'https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/ERP-example/2-3.png',id:5},
      {src:'https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/ERP-example/2-4.png',id:6},
      {src:'https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/ERP-example/2-5.png',id:7},
      {src:'https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/ERP-example/2-6.png',id:8},
      {src:'https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/ERP-example/2-7.png',id:9},
      {src:'https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/ERP-example/2-8.png',id:10},
      {src:'https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/ERP-example/2-9.png',id:11},
      {src:'https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/ERP-example/2-10.png',id:12},
      {src:'https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/ERP-example/2-11.png',id:13},
      {src:'https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/ERP-example/2-12.png',id:14},
      {src:'https://jiazhiqin.oss-cn-chengdu.aliyuncs.com/mini-program/ERP-jump-image/ERP-example/2-13.png',id:15}
    ],
    animations: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.initAnimations(this.data.titleImageList);
    setTimeout(() => {
      this.initAnimationsYu(this.data.gongyuList);
    }, 3000);
    setTimeout(() => {
      this.initAnimationsYong(this.data.yongjinList);
    }, 5000);
    setTimeout(() => {
      this.initAnimationsStar(this.data.starList);
    }, 4000);
    setTimeout(() => {
      this.initAnimationsChengJiao(this.data.chengjiaoList);
    }, 7000);
  },
  showImageFullScreen(event) {
    let arr = [];
    arr.push(event.target.dataset.parmas);
    wx.previewImage({
      urls: arr, //imgUrl 必须是需要预览的图片链接列表，只有一张图片也需要是列表
      success: (res) => {
        console.log("接口调用成功", res);
      },
    });
  },
  onAnimationEnd(e) {
    // 当前动画结束，检查是否是最后一个动画
    const currentIndex = e.currentTarget.dataset.index;
    if (currentIndex === this.data.titleImageList.length - 1) {
      // 如果是最后一个动画，则不需要做任何事，让它结束
      return;
    }
    // 如果不是最后一个动画，手动触发下一个动画
    this.triggerNextAnimation(currentIndex);
  },
  onAnimationGongYuEnd(e) {
    // 当前动画结束，检查是否是最后一个动画
    const currentIndex = e.currentTarget.dataset.index;
    if (currentIndex === this.data.gongyuList.length - 1) {
      // 如果是最后一个动画，则不需要做任何事，让它结束
      return;
    }
    // 如果不是最后一个动画，手动触发下一个动画
    this.triggerNextAnimation(currentIndex);
  },
  onAnimationYongJinEnd(e) {
    // 当前动画结束，检查是否是最后一个动画
    const currentIndex = e.currentTarget.dataset.index;
    if (currentIndex === this.data.yongjinList.length - 1) {
      // 如果是最后一个动画，则不需要做任何事，让它结束
      return;
    }
    // 如果不是最后一个动画，手动触发下一个动画
    this.triggerNextAnimation(currentIndex);
  },
  onAnimationChengJiaoEnd(e) {
    // 当前动画结束，检查是否是最后一个动画
    const currentIndex = e.currentTarget.dataset.index;
    if (currentIndex === this.data.chengjiaoList.length - 1) {
      // 如果是最后一个动画，则不需要做任何事，让它结束
      return;
    }
    // 如果不是最后一个动画，手动触发下一个动画
    this.triggerNextAnimation(currentIndex);
  },
  initAnimations() {
    const duration = 1000; //持续时长
    const delayBetweenAnimations = 200; //每张图片动画的延迟，这里的延迟主要是在下面使用
    this.data.titleImageList.forEach((image, index) => {
      const animation = wx.createAnimation({
        duration: duration,
        timingFunction: "ease",
      });
      // 为每张图片创建一个动画，注意这里设置的是动画间隔，不是步骤间隔
      animation
        // 如果要设置为只向上的话就只需要前面的一开始就向上，然后再回到原为即可
        .translateY("-40rpx") // 开始时向下移动
        .opacity(1) // 开始时透明度为0
        .step({ delay: index * delayBetweenAnimations }) // 设置延迟
        .translateY(0) // 回到原位
        .opacity(1) // 结束时透明度为1
        .step()
        .translateY("40rpx") // 回到原位
        .step()
        .translateY(0) // 结束后回到原位
        .step();
      this.setData({
        [`titleImageList[${index}].animation`]: animation.export(), // 导出动画
      });
    });
  },
  initAnimationsYu() {
    const duration = 1000; //持续时长
    const delayBetweenAnimations = 200; //每张图片动画的延迟，这里的延迟主要是在下面使用
    this.data.gongyuList.forEach((image, index) => {
      const animation = wx.createAnimation({
        duration: duration,
        timingFunction: "ease",
      });
      // 为每张图片创建一个动画，注意这里设置的是动画间隔，不是步骤间隔
      animation
        // 如果要设置为只向上的话就只需要前面的一开始就向上，然后再回到原为即可
        .translateX("20rpx") // 开始时向下移动
        .opacity(1) // 开始时透明度为0
        .step({ delay: index * delayBetweenAnimations }); // 设置延迟
      this.setData({
        [`gongyuList[${index}].animation`]: animation.export(), // 导出动画
      });
    });
  },
  initAnimationsYong() {
    const duration = 1000; //持续时长
    const delayBetweenAnimations = 200; //每张图片动画的延迟，这里的延迟主要是在下面使用
    this.data.yongjinList.forEach((image, index) => {
      const animation = wx.createAnimation({
        duration: duration,
        timingFunction: "ease",
      });
      // 为每张图片创建一个动画，注意这里设置的是动画间隔，不是步骤间隔
      animation
        // 如果要设置为只向上的话就只需要前面的一开始就向上，然后再回到原为即可
        .translateX("-600rpx") // 开始时向下移动
        .opacity(1) // 开始时透明度为0
        .step({ delay: index * delayBetweenAnimations }); // 设置延迟
      this.setData({
        [`yongjinList[${index}].animation`]: animation.export(), // 导出动画
      });
    });
  },
  initAnimationsStar() {
    const duration = 100; //持续时长
    const delayBetweenAnimations = 200; //每张图片动画的延迟，这里的延迟主要是在下面使用
    this.data.starList.forEach((image, index) => {
      const animation = wx.createAnimation({
        duration: duration,
        timingFunction: "ease-in-out",
      });
      // 为每张图片创建一个动画，注意这里设置的是动画间隔，不是步骤间隔
      animation
        // 如果要设置为只向上的话就只需要前面的一开始就向上，然后再回到原为即可
        .translateX(98) // 开始时向下移动
        .opacity(1) // 开始时透明度为0
        .step({ delay: index * delayBetweenAnimations }); // 设置延迟
      this.setData({
        [`starList[${index}].animation`]: animation.export(), // 导出动画
      });
    });
  },
  initAnimationsChengJiao() {
    const duration = 1000; //持续时长
    const delayBetweenAnimations = 200; //每张图片动画的延迟，这里的延迟主要是在下面使用
    this.data.chengjiaoList.forEach((image, index) => {
      const animation = wx.createAnimation({
        duration: duration,
        timingFunction: "ease-in-out",
      });
      // 为每张图片创建一个动画，注意这里设置的是动画间隔，不是步骤间隔
      animation
        // 如果要设置为只向上的话就只需要前面的一开始就向上，然后再回到原为即可
        .translateX("98rpx") // 开始时向下移动
        .opacity(1) // 开始时透明度为0
        .step({ delay: index * delayBetweenAnimations }); // 设置延迟
      this.setData({
        [`chengjiaoList[${index}].animation`]: animation.export(), // 导出动画
      });
    });
  },
  gocell(){
    wx.makePhoneCall({
      phoneNumber: '18881685181'
    });
  },
  getOrderList() {
    const count = wx.getStorageSync("count");
    this.setData({
      cartCount: count,
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},
  goback() {
    wx.navigateBack({
      delta: 1,
    });
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getOrderList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (options) {
    return {
      title: "嘉之勤官网小程序",
      path: "/pages/index/index",
      imageUrl:
        "https://youyougo2.oss-cn-chengdu.aliyuncs.com/0201506f6fc0f4145e34159c2e2ac66b94b96450dd29e5a19d177edc5dad8023.png",
    };
  },
});
